﻿"""""""""""""""""""""""""""VIM Encoding"""""""""""""""""""""""""""
set encoding=utf-8
set langmenu=zh_CN.UTF-8
language messages zh_CN.utf-8
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
if has("gui_running")
    set guioptions-=m
    set guioptions-=T
    set showtabline=0
    set guioptions-=b
endif 
set winaltkeys=no	"Alt 组合键不映射到菜单上
"""""""DirectX
if has('win32') || has('win64')
    set renderoptions=type:directx,renmode:5
end
"""""""最大化开启
if has('win32')
    au GUIEnter * simalt ~x
else
    au GUIEnter * call MaximizeWindow()
endif
function! MaximizeWindow()
    silent !wmctrl -r :ACTIVE: -b add,maximized_vert,maximized_horz
endfunction
"""""""""""""""""""""""""""VIM Encoding"""""""""""""""""""""""""""

set nocompatible
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin

set diffexpr=MyDiff()
function! MyDiff()
    let opt = '-a --binary '
    if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
    if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
    let arg1 = v:fname_in
    if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
    let arg2 = v:fname_new
    if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
    let arg3 = v:fname_out
    if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
    let eq = ''
    if $VIMRUNTIME =~ ' '
        if &sh =~ '\<cmd'
            let cmd = '""' . $VIMRUNTIME . '\diff"'
            let eq = '"'
        else
            let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
        endif
    else
        let cmd = $VIMRUNTIME . '\diff'
    endif
    silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction
"""""""""""""""""""""""""""vim-plug"""""""""""""""""""""""""""
call plug#begin(expand($VIM).'/vimfiles/bundle')

"""""""""""Common
Plug 'majutsushi/tagbar'
Plug 'Shougo/neocomplete.vim'
Plug 'Shougo/context_filetype.vim'
Plug 'Shougo/neosnippet'
Plug 'scrooloose/syntastic'
Plug 'bling/vim-airline'
Plug 'jiangmiao/auto-pairs'
Plug 'DataWraith/auto_mkdir'
Plug 'Yggdroot/LeaderF'
Plug 'Chiel92/vim-autoformat'
Plug 'Yggdroot/indentLine'
Plug 'scrooloose/nerdcommenter'
Plug 'tpope/vim-fugitive'
Plug 'luochen1990/rainbow'
Plug 'lilydjwg/colorizer'
Plug 'tpope/vim-surround'
Plug 'dkprice/vim-easygrep'
Plug 'honza/vim-snippets'
Plug 'tomasr/molokai'
"Plug 'altercation/vim-colors-solarized'
"Plug 'chriskempson/base16-vim'
"Plug 'chriskempson/base16-shell'
"Plug 'richq/cmakecompletion-vim'

"""""""""""Desktop
"""""""C/C++
Plug 'Rip-Rip/clang_complete'
Plug 'twatan/vim-cmake-dict'
Plug 'taxilian/a.vim'
Plug 'octol/vim-cpp-enhanced-highlight'
"""""""Python
Plug 'davidhalter/jedi-vim'
"""""""D
Plug 'idanarye/vim-dutyl'
Plug 'JesseKPhillips/d.vim'

"""""""""""Web
"""""""html/js
Plug 'othree/html5.vim'
Plug 'hail2u/vim-css3-syntax'
Plug 'pangloss/vim-javascript'
Plug 'alvan/vim-closetag'
"""""""PHP
Plug 'shawncplus/phpcomplete.vim'
Plug '2072/PHP-Indenting-for-VIm'
"Plug 'captbaritone/better-indent-support-for-php-with-html'

call plug#end()
filetype plugin indent on
"""""""""""""""""""""""""""vim-plug"""""""""""""""""""""""""""
"""""""""""""""""""""""""""VIM"""""""""""""""""""""""""""
set number "显示行号
syntax on "语法高亮度显示
filetype on  "检测文件的类型
set autoindent "vim使用自动对齐，也就是把当前行的对齐格式应用到下一行(自动缩进）
set cindent "（cindent是特别针对 C语言语法自动缩进）
set tabstop=4
set softtabstop=4  "缩进相关
set shiftwidth=4
set expandtab "展开Tab
set smartindent "依据上面的对齐格式，智能的选择对齐方式，对于类似C语言编写上有用
set showmatch "设置匹配模式，类似当输入一个左括号时会匹配相应的右括号
set incsearch "搜索时自动高亮第一个匹配项
set hlsearch "高亮搜索匹配项
set ignorecase smartcase "智能匹配大小写
set hidden "隐藏未保存缓冲区
let mapleader=',' "leader映射为逗号
noremap \ ,    "映射逗号为\
set wildmode=full
set wildmenu  "命令行补全菜单
set fileformats=unix,dos "优先选择Unix换行符
set colorcolumn=80
set cursorline  "显示当前行位置
set cursorcolumn   "显示当前列位置

"set background=light
"let g:solarized_termcolors=256
"colorscheme solarized   "设置配色方案
colorscheme molokai
"set autochdir  "自动切换工作目录
nnoremap <silent> <leader>scf :cd %:h<TAB><CR>
nnoremap <silent> <leader>ev :e $MYVIMRC<cr>
nnoremap <leader>sv :source $MYVIMRC<cr>
nnoremap <silent> <leader>af :update<CR>:Autoformat<CR>:update<CR>
nnoremap <silent> <leader>bn :bn<CR>
nnoremap <silent> <leader>bp :bp<CR>
nnoremap <silent> <leader>wj <C-w>j
nnoremap <silent> <leader>wk <C-w>k
nnoremap <silent> <leader>wl <C-w>l
nnoremap <silent> <leader>wh <C-w>h
cnoremap <expr> %% getcmdtype() == ':' ? expand('%:h').'/' : '%%'
nnoremap <silent> <leader>nl :nohl<CR>
nnoremap <silent> <leader>qo :copen<CR>
nnoremap <silent> <leader>qc :cclose<CR>
nnoremap <leader>qn :cnext<CR>
nnoremap <leader>qp :cprev<CR>
nnoremap <silent> <leader>lo :lopen<CR>
nnoremap <silent> <leader>lc :lclose<CR>
nnoremap <leader>ln :lnext<CR>
nnoremap <leader>lp :lprev<CR>
nnoremap <silent> <leader>rp :!E:/DeveloperTools/Python34/python.exe %<CR>
set guifont=DejaVu\ Sans\ Mono\ for\ Powerline:h12
set guifontwide=Microsoft_YaHei:h12
"""""""Markdown
augroup markdownACMD
    autocmd!
    autocmd FileType markdown setlocal spell
augroup END

"""""""""""""""""""""""""""VIM"""""""""""""""""""""""""""
"""""""""""""""""""""""""""vim-jedi"""""""""""""""""""""""""""
let g:jedi#force_py_version = 3
let g:jedi#completions_enabled = 0
let g:jedi#auto_vim_configuration = 0
"""""""""""""""""""""""""""vim-jedi"""""""""""""""""""""""""""
"""""""""""""""""""""""""""clang_complete"""""""""""""""""""""""""""
let g:clang_complete_auto = 0
let g:clang_auto_select = 0
let g:clang_default_keymappings = 0
let g:clang_use_library = 1
let g:clang_restore_cr_imap = ''
let g:clang_complete_copen = 0
let g:clang_periodic_quickfix = 0
let g:clang_complete_macros = 1
let g:clang_complete_patterns = 1
let g:clang_user_options='-std=c++11 -IE:/developertools/TDM-GCC/lib/gcc/mingw32/5.1.0/include/c++ -IE:/developertools/TDM-GCC/lib/gcc/mingw32/5.1.0/include/c++/mingw32 -IE:/developertools/TDM-GCC/lib/gcc/mingw32/5.1.0/include/c++/backward -IE:/developertools/TDM-GCC/lib/gcc/mingw32/5.1.0/include -IE:/developertools/TDM-GCC/lib/gcc/mingw32/5.1.0/include-fixed -IE:/developertools/TDM-GCC/include'
"let g:AutoPairsMapCR = 0   "修复 auto-pairs 回车键冲突
"imap <silent><CR> <CR><Plug>AutoPairsReturn
"""""""""""""""""""""""""""clang_complete"""""""""""""""""""""""""""
"""""""""""""""""""""""""""neocomplete"""""""""""""""""""""""""""
let g:neocomplete#enable_at_startup = 1
let g:neocomplete#enable_smart_case = 1
let g:neocomplete#sources#syntax#min_keyword_length = 1
let g:neocomplete#lock_buffer_name_pattern = '\*ku\*'
let g:neocomplete#sources#dictionary#dictionaries = {'default' : '' , 'cmake' : $VIM.'/vimfiles/bundle/vim-cmake-dict/dict/cmake.dict'}
if !exists('g:neocomplete#keyword_patterns') 
    let g:neocomplete#keyword_patterns = {} 
endif 
let g:neocomplete#keyword_patterns['default'] = '\h\w*'
inoremap <expr><C-g> neocomplete#undo_completion()
inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR>
function! s:my_cr_function()
    return pumvisible() ? "\<C-y>" : "\<CR>"
endfunction
"inoremap <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>"
inoremap <expr><S-Tab> pumvisible() ? "\<C-p>" : "\<Tab>"
inoremap <expr><BS> neocomplete#smart_close_popup()."\<C-h>"
inoremap <expr><Space> pumvisible() ? "\<C-y>" : "\<Space>"
autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags
autocmd FileType python setlocal omnifunc=jedi#completions
autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags
autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS

if !exists('g:neocomplete#force_omni_input_patterns')
    let g:neocomplete#force_omni_input_patterns = {}
endif
let g:neocomplete#force_omni_input_patterns.c = '[^.[:digit:] *\t]\%(\.\|->\)\w*'
let g:neocomplete#force_omni_input_patterns.cpp ='[^.[:digit:] *\t]\%(\.\|->\)\w*\|\h\w*::\w*'
let g:neocomplete#force_omni_input_patterns.python = '\%([^. \t]\.\|^\s*@\|^\s*from\s.\+import \|^\s*from \|^\s*import \)\w*'
let g:neocomplete#force_omni_input_patterns.d = '\%([^. \t]\.\|^\s*@\|^\s*import\s\+\%(\%(\h\w\+\%([:=]\h\w+\)\?\)\+\s*,\s*\)*\%(\h\w\+[:=]\)*\)\w*'

if !exists('g:neocomplete#sources#omni#input_patterns')
  let g:neocomplete#sources#omni#input_patterns = {}
endif
let g:neocomplete#sources#omni#input_patterns.php = '\%([^. \t]->\%(\h\w*\)\?\|\h\w*::\%(\h\w*\)\?\|$\%(\h\w*\)\?\)\|\%(<\|\s[[:alnum:]-]*\)\|\%(^\s\+\w\+\|\w\+[):;]\?\s\+\w*\|[@!]\)'

inoremap <silent><A-/> <c-x><c-o>
"""""""""""""""""""""""""""neocomplete"""""""""""""""""""""""""""
"""""""""""""""""""""""""""neosnippet"""""""""""""""""""""""""""
imap <C-k>     <Plug>(neosnippet_expand_or_jump)
smap <C-k>     <Plug>(neosnippet_expand_or_jump)
xmap <C-k>     <Plug>(neosnippet_expand_target)
imap <expr><TAB> pumvisible() ? "\<C-n>" : neosnippet#expandable_or_jumpable() ? "\<Plug>(neosnippet_expand_or_jump)" : "\<TAB>"
smap <expr><TAB> neosnippet#expandable_or_jumpable() ? "\<Plug>(neosnippet_expand_or_jump)" : "\<TAB>"
if has('conceal')
    set conceallevel=2 concealcursor=niv
endif
let g:neosnippet#enable_snipmate_compatibility = 1
let g:neosnippet#snippets_directory=$VIM.'/vimfiles/bundle/vim-snippets/snippets'
let g:neosnippet#disable_runtime_snippets = { '_' : 1}
autocmd FileType php NeoSnippetSource $VIM/vimfiles/bundle/vim-snippets/snippets/html.snippets
if filereadable('userinfo.vim')    "插入 snippets 所需的个人信息
    source ./userinfo.vim
endif
"""""""""""""""""""""""""""neosnippet"""""""""""""""""""""""""""
"""""""""""""""""""""""""""vim-autoformat"""""""""""""""""""""""""""
let g:formatdef_my_custom_d = '"astyle --mode=c -z2 --style=ansi -pcH".(&expandtab ? "s".&shiftwidth : "t")'
let g:formatters_d = ['my_custom_d']
let g:formatdef_my_custom_c = '"astyle --mode=c -z2 --style=ansi -pcH".(&expandtab ? "s".&shiftwidth : "t")'
let g:formatters_c=['my_custom_c']
let g:formatters_cpp = ['my_custom_cpp']
let g:formatdef_my_custom_cpp = '"astyle --mode=c -z2 --style=ansi -pcH".(&expandtab ? "s".&shiftwidth : "t")'
"""""""""""""""""""""""""""vim-autoformat"""""""""""""""""""""""""""
"""""""""""""""""""""""""""syntastic"""""""""""""""""""""""""""
let g:syntastic_always_populate_loc_list = 1  "自动更新错误列表
let g:syntastic_auto_loc_list = 1
let g:syntastic_cpp_compiler_options = ' -std=c++11 -Wall'  " C++11支持
let g:syntastic_python_python_exec = 'E:/DeveloperTools/Python34' 
let g:syntastic_check_on_open = 0
let g:syntastic_check_on_wq = 0
"""""""""""""""""""""""""""syntastic"""""""""""""""""""""""""""
"""""""""""""""""""""""""""ctags"""""""""""""""""""""""""""
nnoremap <silent> <leader>gtf :!ctags -R --exclude=.git<CR>
set tags=tags
autocmd vimenter * TagbarToggle
let g:tagbar_left = 1
let g:tagbar_width = 25
let g:tagbar_type_d = {'ctagstype' : 'd',  'kinds' : [  'c:classes:0:1',  'f:functions',  'g:enums',  'u:unions',  's:structs',  'm:members'  ], 'sro': '.',  'kind2scope' : {  'c' : 'class',  'g' : 'enum',  's' : 'struct',  'u' : 'union' },  'scope2kind' : {  'enum' : 'g',  'class' : 'c',  'struct' : 's',  'union' : 'u'  }  }
"""""""""""""""""""""""""""ctags"""""""""""""""""""""""""""
"""""""""""""""""""""""""""DCD"""""""""""""""""""""""""""
call dutyl#register#tool('dcd-client','E:/DeveloperTools/DCD/dcd-client.exe') 
call dutyl#register#tool('dcd-server','E:/DeveloperTools/DCD/dcd-server.exe')
let g:dutyl_stdImportPaths=['E:/DeveloperTools/dmd2/src/phobos', 'E:/DeveloperTools/dmd2/src/druntime/import', 'E:/DeveloperTools/dmd2/src/tango']
let g:dutyl_neverAddClosingParen = 1
"""""""""""""""""""""""""""DCD"""""""""""""""""""""""""""
"""""""""""""""""""""""""""airline"""""""""""""""""""""""""""
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#syntastic#enabled = 1
let g:airline#extensions#tagbar#enabled = 1
let g:airline#extensions#tagbar#flags = 'f'
let g:airline#extensions#branch#enabled = 1
let g:airline#extensions#branch#empty_message = ''
let g:airline#extensions#branch#displayed_head_limit = 10
let g:airline_powerline_fonts = 1
"""""""""""""""""""""""""""airline"""""""""""""""""""""""""""
"""""""""""""""""""""""""""ultisnips"""""""""""""""""""""""""""
"let g:UltiSnipsJumpForwardTrigger="<c-b>" 
"let g:UltiSnipsExpandTrigger="<c-e>"
"let g:UltiSnipsUsePythonVersion = 2 "US强制使用Python 2.X以兼容 clang_complete
"if filereadable('userinfo.vim')    "插入 snippets 所需的个人信息
    "source ./userinfo.vim
"endif
"""""""""""""""""""""""""""ultisnips"""""""""""""""""""""""""""
"""""""""""""""""""""""""""visual-star-search"""""""""""""""""""""""""""
"""Code from:https://github.com/nelstrom/vim-visual-star-search/blob/master/plugin/visual-star-search.vim
function! s:VSetSearch(cmdtype)
    let temp = @s
    norm! gv"sy
    let @/ = '\V' . substitute(escape(@s, a:cmdtype.'\'), '\n', '\\n', 'g')
    let @s = temp
endfunction
xnoremap * :<C-u>call <SID>VSetSearch('/')<CR>/<C-R>=@/<CR><CR>
xnoremap # :<C-u>call <SID>VSetSearch('?')<CR>?<C-R>=@/<CR><CR>
"""""""""""""""""""""""""""visual-star-search"""""""""""""""""""""""""""
"""""""""""""""""""""""""""rainbow"""""""""""""""""""""""""""
let g:rainbow_active = 1
"""""""""""""""""""""""""""rainbow"""""""""""""""""""""""""""
"""""""""""""""""""""""""""vim-javascript"""""""""""""""""""""""""""
let g:javascript_enable_domhtmlcss = 1
"""""""""""""""""""""""""""vim-javascript"""""""""""""""""""""""""""
"""""""""""""""""""""""""""HTML"""""""""""""""""""""""""""
let g:closetag_filenames = '*.html,*.xhtml,*.phtml,*.php'  "closetag
let g:html_indent_inctags = "body,head,tbody"	" 缩进body head
let g:html_indent_script1 = "inc"	" 缩进<script>标签
let g:html_indent_style1 = "inc"	" 缩进<style>标签
runtime macros/matchit.vim   "支持使用 % 在 XML 标签间跳转
"""""""""""""""""""""""""""HTML"""""""""""""""""""""""""""
